package com.yao.club.controller;

import com.netease.yidun.sdk.core.utils.StringUtils;
import com.yao.club.entity.result.ResponseEntity;

import com.yao.club.entity.vo.HotTopicsVO;
import com.yao.club.entity.vo.SearchSuggestionVO;
import com.yao.club.service.PostsSearchService;
import com.yao.club.token.PassToken;
import com.yao.club.utils.ResponseUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/app/search")
@Api(value = "俱乐部帖子-搜索模块", description = "俱乐部帖子-搜索模块接口", tags = "俱乐部帖子-搜索模块")
public class PostsSearchController {

    @Autowired
    private PostsSearchService postsSearchService;

    @Resource
    HttpServletRequest request;

    @PassToken
    @GetMapping("/hotTopics")
    @ApiOperation(value = "获取热门话题推荐", notes = "返回热门话题列表")
    public ResponseEntity<HotTopicsVO> getHotTopics() {
        return postsSearchService.getHotTopics();
    }

    @PassToken
    @GetMapping("/searchKeywordList")
    @ApiOperation(value = "获取话题搜索建议", notes = "根据关键字返回相关话题建议")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "keyword", value = "搜索关键词", required = true)
    })
    public ResponseEntity<List<SearchSuggestionVO>> searchKeywordList(
            @RequestParam String keyword) {
        if (StringUtils.isEmpty(keyword)) {
            return ResponseUtils.failed("搜索关键词不能为空");
        }
        return postsSearchService.searchKeywordList(keyword);
    }


}
